package com.example.classes;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.itas.R;


public class ReviewContainerAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	private int layout;
	private TextView title_view;
	private TextView author_view;
	private TextView date_view;
	private TextView content_view;
	private RatingBar rating_bar;
	
	ArrayList<ReviewInfo> reviewInfoBeanList = new ArrayList<ReviewInfo>();
	
	
	public ReviewContainerAdapter(Context context, int layout, ArrayList<ReviewInfo> infoBeanList){
		this.context = context;
		this.layout = layout;
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.reviewInfoBeanList = infoBeanList;
		//reviewInfoBeanList.add(new ReviewInfo("It is Nice", "Cool", 5));//temp data
		//reviewInfoBeanList.add(new ReviewInfo("It is Nice2", "Cool2", 3));//temp data
	}
	
	public int getCount() {
		// TODO Auto-generated method stub
		return reviewInfoBeanList.size();
	}

	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return reviewInfoBeanList.get(pos).getTitle();
	}

	public long getItemId(int pos) {
		// TODO Auto-generated method stub
		return pos;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final int finalposition = position;
		if(convertView==null){
            convertView = inflater.inflate(layout, parent, false);
        }
		title_view = (TextView) convertView.findViewById(R.id.review_title_view);
		author_view = (TextView) convertView.findViewById(R.id.review_author_view);
		date_view = (TextView) convertView.findViewById(R.id.review_date_view);
		content_view = (TextView) convertView.findViewById(R.id.review_content_view);
		rating_bar = (RatingBar) convertView.findViewById(R.id.review_ratingBar);
		
		title_view.setText(reviewInfoBeanList.get(finalposition).getTitle());
		author_view.setText(reviewInfoBeanList.get(finalposition).getUserName());
		date_view.setText(reviewInfoBeanList.get(finalposition).getDate());
		content_view.setText(reviewInfoBeanList.get(finalposition).getContents());
		rating_bar.setRating(reviewInfoBeanList.get(finalposition).getRating());
		
		return convertView;
	}

}
